package org.jeecg.common.modules.settlement.service.impl;

import org.jeecg.common.modules.settlement.entity.Settlement;
import org.jeecg.common.modules.settlement.entity.SettlementDetail;
import org.jeecg.common.modules.settlement.mapper.SettlementDetailMapper;
import org.jeecg.common.modules.settlement.service.ISettlementDetailService;
import org.jeecg.common.modules.settlement.vo.SettlementDetailReqVo;
import org.jeecg.common.util.enums.SettlementDetailTypeEnum;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * @Description: settlement_detail
 * @Author: jeecg-boot
 * @Date:   2020-09-03
 * @Version: V1.0
 */
@Service
public class SettlementDetailServiceImpl extends ServiceImpl<SettlementDetailMapper, SettlementDetail> implements ISettlementDetailService {

    @Resource
    private SettlementDetailMapper settlementDetailMapper;

    @Override
    public void initSettlementDetail(Settlement settlement, SettlementDetailTypeEnum type, String userId, BigDecimal amount,BigDecimal ratio,String createUser){
        SettlementDetail detail = new SettlementDetail();
        detail.setSettlementId(settlement.getId());
        detail.setType(type.getCode());
        detail.setUserId(userId);
        detail.setSettlementAmount(amount);
        detail.setGivingAmount(BigDecimal.ZERO);
        detail.setRatio(ratio);
        detail.setCreateTime(new Date());
        detail.setCreateUser(createUser);
        save(detail);
    }

    @Override
    public List<SettlementDetailReqVo> getSettlementDetail(Integer settlementId){
        return settlementDetailMapper.settlementDetail(settlementId);
    }
}
